
new Vue({
    el: '#app',
    delimiters:['[[', ']]'],

    data: {
        tags_in_homepage: [],
        tags_in_chat_room_page: [],
    },

    methods: {
        /**
         * 请求首页房间品类列表
         */
        requestRoomTagListInHomepage() {
            let url = "{% url 'gma:api_get_room_tag_list_in_homepage' %}";
            new my_ajax(url, {}, '', '', (data) => {
                console.table(data);
                this.tags_in_homepage = data;

                this.tags_in_homepage.forEach(tag => {
                    tag.edit_url = `/gma/config/room_tag/${tag.tag_id}/edit/`;
                });
            });
        },

        /**
         * 点击首页的房间分类
         * @param tag
         */
        clickRoomTagShowInHomepage(tag) {
            if (tag.show_in_homepage === 1) {
                this.disableRoomTagInHomepage(tag.tag_id);
            } else {
                this.enableRoomTagInHomepage(tag.tag_id);
            }
        },

        /**
         * 启用首页的房间品类
         *
         * @param room_tag_id
         */
        enableRoomTagInHomepage(room_tag_id) {
            let data = {
                'room_tag_id': room_tag_id,
            };

            let url = "{% url 'gma:api_enable_room_tag_in_homepage' %}";
            new my_ajax(url, data, '', '', () => {
                show_toast('成功开启');
                this.requestRoomTagListInHomepage();
            });
        },

        /**
         * 禁用首页的房间品类
         *
         * @param room_tag_id
         */
        disableRoomTagInHomepage(room_tag_id) {
            let data = {
                'room_tag_id': room_tag_id,
            };

            let url = "{% url 'gma:api_disable_room_tag_in_homepage' %}";
            new my_ajax(url, data, '', '', () => {
                show_toast('成功关闭');
                this.requestRoomTagListInHomepage();
            });
        },

        /**
         * 请求聊天室房间品类列表
         */
        requestRoomTagListInChatRoomPage() {
            let url = "{% url 'gma:api_get_room_tag_list_in_chat_room_page' %}";
            new my_ajax(url, {}, '', '', (data) => {
                console.table(data);
                this.tags_in_chat_room_page = data;

                this.tags_in_chat_room_page.forEach(tag => {
                    tag.edit_url = `/gma/config/room_tag/${tag.tag_id}/edit/`;
                });
            });
        },

        /**
         * 点击聊天室的房间分类
         * @param tag
         */
        clickRoomTagShowInChatRoomPage(tag) {
            if (tag.show_in_chat_room_page === 1) {
                this.disableRoomTagInChatRoomPage(tag.tag_id);
            } else {
                this.enableRoomTagInChatRoomPage(tag.tag_id);
            }
        },

        /**
         * 启用聊天室的房间品类
         *
         * @param room_tag_id
         */
        enableRoomTagInChatRoomPage(room_tag_id) {
            let data = {
                'room_tag_id': room_tag_id,
            };

            let url = "{% url 'gma:api_enable_room_tag_in_chat_room_page' %}";
            new my_ajax(url, data, '', '', () => {
                show_toast('成功开启');
                this.requestRoomTagListInChatRoomPage();
            });
        },

        /**
         * 禁用聊天室的房间品类
         *
         * @param room_tag_id
         */
        disableRoomTagInChatRoomPage(room_tag_id) {
            let data = {
                'room_tag_id': room_tag_id,
            };

            let url = "{% url 'gma:api_disable_room_tag_in_chat_room_page' %}";
            new my_ajax(url, data, '', '', () => {
                show_toast('成功关闭');
                this.requestRoomTagListInChatRoomPage();
            });
        },
    },

    mounted() {
        this.requestRoomTagListInHomepage();
        this.requestRoomTagListInChatRoomPage();
    },
});
